package co.fitstart.coach.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Service;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.utils.DateFormatUtils;
import com.demo2do.core.utils.DateUtils;

import co.fitstart.coach.dao.SigninRecordDao;
import co.fitstart.coach.service.SigninRecordService;
import co.fitstart.entity.course.schedule.SigninRecord;
import co.fitstart.entity.principal.Principal;

@Service("signinRecordService")
public class SigninRecordServiceImpl implements SigninRecordService{
    
    @Dynamic
    private SigninRecordDao signinRecordDao;

    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.SigninRecordService#getDaySigninAmount(co.fitstart.entity.principal.Principal, java.util.Date)
     */
    public int getDaySigninAmount(Principal coach, Date date) {
        String thisDate = DateFormatUtils.format(date, "yyyy-MM-dd");
        Date startTime = DateUtils.parseDate(thisDate + " 00:00:00", "yyyy-MM-dd HH:mm:ss");
        Date endTime = DateUtils.parseDate(thisDate + " 23:23:59", "yyyy-MM-dd HH:mm:ss");
        
        return signinRecordDao.getDaySigninAmount(coach, startTime, endTime);
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.SigninRecordService#getSigninAmount(co.fitstart.entity.principal.Principal)
     */
    public int getSigninAmount(Principal coach) {
        return signinRecordDao.getSigninAmount(coach);
    }

    /*
     * (non-Javadoc)
     * @see co.fitstart.coach.service.SigninRecordService#list(co.fitstart.entity.principal.Principal)
     */
    public List<SigninRecord> list(Principal coach) {
        return signinRecordDao.list(coach);
    }

}
